package main

import (
	"io/ioutil"
	"fmt"
)

func func_if() {
	const filename = "abc.txt"
	/*
	contents, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s\n", contents)
	}
	*/
	//可初始化一个值,生存期只有在if的块有效
	if contents, err := ioutil.ReadFile(filename); err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s\n", contents)
	}
}

func func_switch(score int) string {
	g := ""
	//可以不加入条件 直接在case里面判断
	//另外可以同if一样,在条件前可以加入一条语句
	//用;分割
	switch {
	case score < 0 || score > 100:
		panic(fmt.Sprintf(
			"Wrong score:%d", score,
		))
	case score < 60:
		g = "F"
	case score < 80:
		g = "C"
	case score < 90:
		g = "B"
	default:
		g = "A"
	}

	switch a := score / 10 + 1; a {
	case 0:
		//让程序终止
		panic(fmt.Sprintf(
			"Wrong score:%d", score,
		))
	case 2:
		g = "F"
	case 4:
		g = "C"
	case 6:
		g = "B"
	default:
		g = "A"
	}
	return g
}

func main() {
	fmt.Println(
		func_switch(0),
		func_switch(60),
		func_switch(80),
		func_switch(90),
		func_switch(100),
		func_switch(0),
	)
}
